home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Archiver.java < prev    next >
Text File  |  1998-11-03  |  34KB  |  1,299 lines

  1. package com.symantec.itools.tools.archive;
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileReader;
  8. import java.util.StringTokenizer;
  9. import java.util.Vector;
  10. import com.symantec.itools.frameworks.application.commandline.Application;
  11. import com.symantec.itools.frameworks.application.commandline.BooleanOption;
  12. import com.symantec.itools.frameworks.application.commandline.EmptyOption;
  13. import com.symantec.itools.frameworks.application.commandline.InvalidArgumentException;
  14. import com.symantec.itools.frameworks.application.commandline.MissingArgumentsException;
  15. import com.symantec.itools.frameworks.application.commandline.Option;
  16. import com.symantec.itools.frameworks.application.commandline.StringArrayOption;
  17. import com.symantec.itools.frameworks.application.commandline.StringOption;
  18. import com.symantec.itools.io.Directory;
  19. import com.symantec.itools.io.NotDirectoryException;
  20. import com.symantec.itools.lang.AccessiblePlatform;
  21. import com.symantec.itools.lang.Debug;
  22. import com.symantec.itools.lang.DynamicClassException;
  23. import com.symantec.itools.util.Properties;
  24.  
  25.  
  26. /**
  27.  * @author Symantec Internet Tools Division
  28.  * @version 1.0
  29.  * @since VCafe 3.0
  30.  */
  31.  
  32. public class Archiver
  33.     extends Application
  34. {
  35.  
  36.     /**
  37.      * @since VCafe 3.0
  38.      */
  39.     protected final static String VERSION = "Beta 1 - 0.0.0";
  40.  
  41.     /**
  42.      * @since VCafe 3.0
  43.      */
  44.     protected Options options;
  45.  
  46.     /**
  47.      * @since VCafe 3.0
  48.      */
  49.     protected TypeValidator validatorType;
  50.  
  51.     /**
  52.      * @since VCafe 3.0
  53.      */
  54.     protected TypeArchiver archiverType;
  55.  
  56.     /**
  57.      * @since VCafe 3.0
  58.      */
  59.     protected TypeSigning signingType;
  60.  
  61.     /**
  62.      * @author Symantec Internet Tools Division
  63.      * @version 1.0
  64.      * @since VCafe 3.0
  65.      */
  66.     class TypeOption
  67.         extends StringOption
  68.     {
  69.         /**
  70.          * @param args TODO
  71.          * @param startIndex TODO
  72.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  73.          * @since VCafe 3.0
  74.          */
  75.         public void parseArg(String[] args, int startIndex)
  76.             throws InvalidArgumentException
  77.         {
  78.             setType(getString(args, startIndex));
  79.         }
  80.     }
  81.  
  82.  
  83.     /**
  84.      * @author Symantec Internet Tools Division
  85.      * @version 1.0
  86.      * @since VCafe 3.0
  87.      */
  88.     class VerboseOption
  89.         extends BooleanOption
  90.     {
  91.         /**
  92.          * @param args TODO
  93.          * @param startIndex TODO
  94.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  95.          * @since VCafe 3.0
  96.          */
  97.         public void parseArg(String[] args, int startIndex)
  98.             throws InvalidArgumentException
  99.         {
  100.             setVerbose(getBoolean(args, startIndex));
  101.         }
  102.     }
  103.  
  104.     /**
  105.      * @author Symantec Internet Tools Division
  106.      * @version 1.0
  107.      * @since VCafe 3.0
  108.      */
  109.     class FilesOption
  110.         extends StringArrayOption
  111.     {
  112.         /**
  113.          * @param args TODO
  114.          * @param startIndex TODO
  115.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  116.          * @since VCafe 3.0
  117.          */
  118.         public void parseArg(String[] args, int startIndex)
  119.             throws InvalidArgumentException
  120.         {
  121.             int i;
  122.  
  123.             for(i = startIndex + 1; i < args.length; i++)
  124.             {
  125.                 char c;
  126.  
  127.                 c = args[i].charAt(0);
  128.  
  129.                 if((c == '-') || (c == '/'))
  130.                 {
  131.                     break;
  132.                 }
  133.             }
  134.  
  135.             setFiles(getStringArray(args, startIndex, i - startIndex - 1));
  136.         }
  137.     }
  138.  
  139.     /**
  140.      * @author Symantec Internet Tools Division
  141.      * @version 1.0
  142.      * @since VCafe 3.0
  143.      */
  144.     class EntriesOption
  145.         extends StringArrayOption
  146.     {
  147.         /**
  148.          * @param args TODO
  149.          * @param startIndex TODO
  150.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  151.          * @since VCafe 3.0
  152.          */
  153.         public void parseArg(String[] args, int startIndex)
  154.             throws InvalidArgumentException
  155.         {
  156.             int i;
  157.  
  158.             for(i = startIndex + 1; i < args.length; i++)
  159.             {
  160.                 char c;
  161.  
  162.                 c = args[i].charAt(0);
  163.  
  164.                 if((c == '-') || (c == '/'))
  165.                 {
  166.                     break;
  167.                 }
  168.             }
  169.  
  170.             setEntries(getStringArray(args, startIndex, i - startIndex - 1));
  171.         }
  172.     }
  173.  
  174.     /**
  175.      * @author Symantec Internet Tools Division
  176.      * @version 1.0
  177.      * @since VCafe 3.0
  178.      */
  179.     class DebugOption
  180.         extends BooleanOption
  181.     {
  182.         /**
  183.          * @param args TODO
  184.          * @param startIndex TODO
  185.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  186.          * @since VCafe 3.0
  187.          */
  188.         public void parseArg(String[] args, int startIndex)
  189.             throws InvalidArgumentException
  190.         {
  191.             setDebug(getBoolean(args, startIndex));
  192.         }
  193.     }
  194.  
  195.     /**
  196.      * @author Symantec Internet Tools Division
  197.      * @version 1.0
  198.      * @since VCafe 3.0
  199.      */
  200.     class OverwriteOption
  201.         extends BooleanOption
  202.     {
  203.         /**
  204.          * @param args TODO
  205.          * @param startIndex TODO
  206.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  207.          * @since VCafe 3.0
  208.          */
  209.         public void parseArg(String[] args, int startIndex)
  210.             throws InvalidArgumentException
  211.         {
  212.             setOverwrite(getBoolean(args, startIndex));
  213.         }
  214.     }
  215.  
  216.     /**
  217.      * @author Symantec Internet Tools Division
  218.      * @version 1.0
  219.      * @since VCafe 3.0
  220.      */
  221.     class OutOption
  222.         extends StringArrayOption
  223.     {
  224.         /**
  225.          * @param args TODO
  226.          * @param startIndex TODO
  227.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  228.          * @since VCafe 3.0
  229.          */
  230.         public void parseArg(String[] args, int startIndex)
  231.             throws InvalidArgumentException
  232.         {
  233.             int          i;
  234.             String[]     array;
  235.             StringBuffer buf;
  236.  
  237.             for(i = startIndex + 1; i < args.length; i++)
  238.             {
  239.                 if(args[i].endsWith("\""))
  240.                 {
  241.                     i++;
  242.                     break;
  243.                 }
  244.             }
  245.  
  246.             array = getStringArray(args, startIndex, i - startIndex - 1);
  247.             buf   = new StringBuffer();
  248.             
  249.             for(i = 0; i < array.length; i++)
  250.             {
  251.                 buf.append(array[i]).append(' ');
  252.             }
  253.             
  254.             setOutputLocation(buf.toString().trim());
  255.         }
  256.     }
  257.  
  258.     /**
  259.      * @author Symantec Internet Tools Division
  260.      * @version 1.0
  261.      * @since VCafe 3.0
  262.      */
  263.     class TempDirOption
  264.         extends StringArrayOption
  265.     {
  266.         /**
  267.          * @param args TODO
  268.          * @param startIndex TODO
  269.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  270.          * @since VCafe 3.0
  271.          */
  272.         public void parseArg(String[] args, int startIndex)
  273.             throws InvalidArgumentException
  274.         {
  275.             int          i;
  276.             String[]     array;
  277.             StringBuffer buf;
  278.  
  279.             for(i = startIndex + 1; i < args.length; i++)
  280.             {
  281.                 if(args[i].endsWith("\""))
  282.                 {
  283.                     i++;
  284.                     break;
  285.                 }
  286.             }
  287.  
  288.             array = getStringArray(args, startIndex, i - startIndex - 1);
  289.             buf   = new StringBuffer();
  290.             
  291.             for(i = 0; i < array.length; i++)
  292.             {
  293.                 buf.append(array[i]).append(' ');
  294.             }
  295.             
  296.             setTempDir(buf.toString().trim());
  297.         }
  298.     }
  299.  
  300.     /**
  301.      * @author Symantec Internet Tools Division
  302.      * @version 1.0
  303.      * @since VCafe 3.0
  304.      */
  305.     class DebugLogOption
  306.         extends StringOption
  307.     {
  308.         /**
  309.          * @param args TODO
  310.          * @param startIndex TODO
  311.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  312.          * @since VCafe 3.0
  313.          */
  314.         public void parseArg(String[] args, int startIndex)
  315.             throws InvalidArgumentException
  316.         {
  317.             setDebugLog(getString(args, startIndex));
  318.         }
  319.     }
  320.  
  321.     /**
  322.      * @author Symantec Internet Tools Division
  323.      * @version 1.0
  324.      * @since VCafe 3.0
  325.      */
  326.     class ClasspathOption
  327.         extends StringArrayOption
  328.     {
  329.         /**
  330.          * @param args TODO
  331.          * @param startIndex TODO
  332.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  333.          * @since VCafe 3.0
  334.          */
  335.         public void parseArg(String[] args, int startIndex)
  336.             throws InvalidArgumentException
  337.         {
  338.             int          i;
  339.             String[]     array;
  340.             StringBuffer buf;
  341.  
  342.             for(i = startIndex + 1; i < args.length; i++)
  343.             {
  344.                 if(args[i].endsWith("\""))
  345.                 {
  346.                     i++;
  347.                     break;
  348.                 }
  349.             }
  350.  
  351.             array = getStringArray(args, startIndex, i - startIndex - 1);
  352.             buf   = new StringBuffer();
  353.             
  354.             for(i = 0; i < array.length; i++)
  355.             {
  356.                 buf.append(array[i]).append(' ');
  357.             }
  358.             
  359.             setClasspath(buf.toString().trim());
  360.         }
  361.     }
  362.  
  363.     /**
  364.      * @author Symantec Internet Tools Division
  365.      * @version 1.0
  366.      * @since VCafe 3.0
  367.      */
  368.     class ResponseFileOption
  369.         extends EmptyOption
  370.     {
  371.         /**
  372.          * @param args TODO
  373.          * @param startIndex TODO
  374.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  375.          * @since VCafe 3.0
  376.          */
  377.         public void parseArg(String[] args, int startIndex)
  378.             throws InvalidArgumentException
  379.         {
  380.             if(args[startIndex].startsWith("@"))
  381.             {
  382.                 try
  383.                 {
  384.                     setResponseFile(args[startIndex].substring(1));
  385.                 }
  386.                 catch(IOException ex)
  387.                 {
  388.                     Debug.logException(ex);
  389.                 }
  390.             }
  391.         }
  392.     }
  393.  
  394.     /**
  395.      * @author Symantec Internet Tools Division
  396.      * @version 1.0
  397.      * @since VCafe 3.0
  398.      */
  399.     class HelpOption
  400.         extends EmptyOption
  401.     {
  402.         /**
  403.          * @param args TODO
  404.          * @param startIndex TODO
  405.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  406.          * @since VCafe 3.0
  407.          */
  408.         public void parseArg(String[] args, int startIndex)
  409.             throws InvalidArgumentException
  410.         {
  411.             showHelp();
  412.         }
  413.     }
  414.  
  415.     /**
  416.      * @author Symantec Internet Tools Division
  417.      * @version 1.0
  418.      * @since VCafe 3.0
  419.      */
  420.     class SignerOption
  421.         extends StringOption
  422.     {
  423.         /**
  424.          * @param args TODO
  425.          * @param startIndex TODO
  426.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  427.          * @since VCafe 3.0
  428.          */
  429.         public void parseArg(String[] args, int startIndex)
  430.             throws InvalidArgumentException
  431.         {
  432.             setSigner(getString(args, startIndex));
  433.         }
  434.     }
  435.  
  436.     /**
  437.      * @author Symantec Internet Tools Division
  438.      * @version 1.0
  439.      * @since VCafe 3.0
  440.      */
  441.     class SignerArgsOption
  442.         extends StringArrayOption
  443.     {
  444.         /**
  445.          * @param args TODO
  446.          * @param startIndex TODO
  447.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  448.          * @since VCafe 3.0
  449.          */
  450.         public void parseArg(String[] args, int startIndex)
  451.             throws InvalidArgumentException
  452.         {
  453.             int          i;
  454.             String[]     array;
  455.             StringBuffer buf;
  456.  
  457.             for(i = startIndex + 1; i < args.length; i++)
  458.             {
  459.                 args[i] = args[i].trim();
  460.                 
  461.                 if(args[i].startsWith("\\\""))
  462.                 {
  463.                     args[i] = args[i].substring(1);
  464.                 }
  465.                 
  466.                 if(args[i].endsWith("\""))
  467.                 {
  468.                     // remove "\" from embeded quoted file
  469.                     if(args[i].endsWith("\\\""))
  470.                     {
  471.                         args[i] = args[i].substring(0, args[i].length() - 2) + "\"";
  472.                     }
  473.                     // if we have "\"" then we are done - remove embeded \
  474.                     else if(args[i].endsWith("\"\""))
  475.                     {
  476.                         args[i] = args[i].substring(0, args[i].length() - 3) + "\"\"";
  477.                         i++;
  478.                         break;
  479.                     }
  480.                     else
  481.                     {
  482.                         i++;
  483.                         break;
  484.                     }
  485.                 }
  486.             }
  487.  
  488.             array = getStringArray(args, startIndex, i - startIndex - 1);
  489.             buf   = new StringBuffer();
  490.             
  491.             for(i = 0; i < array.length; i++)
  492.             {
  493.                 buf.append(array[i]).append(' ');
  494.             }            
  495.             
  496.             setSignerArgs(buf.toString().trim());
  497.         }
  498.     }
  499.  
  500.     /**
  501.      * @author Symantec Internet Tools Division
  502.      * @version 1.0
  503.      * @since VCafe 3.0
  504.      */
  505.     class ArchiverArgsOption
  506.         extends StringArrayOption
  507.     {
  508.         /**
  509.          * @param args TODO
  510.          * @param startIndex TODO
  511.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  512.          * @since VCafe 3.0
  513.          */
  514.         public void parseArg(String[] args, int startIndex)
  515.             throws InvalidArgumentException
  516.         {
  517.             int          i;
  518.             String[]     array;
  519.             StringBuffer buf;
  520.  
  521.             for(i = startIndex + 1; i < args.length; i++)
  522.             {
  523.                 args[i] = args[i].trim();
  524.                 
  525.                 if(args[i].startsWith("\\\""))
  526.                 {
  527.                     args[i] = args[i].substring(1);
  528.                 }
  529.                 
  530.                 if(args[i].endsWith("\""))
  531.                 {
  532.                     if(args[i].endsWith("\\\""))
  533.                     {
  534.                         args[i] = args[i].substring(0, args[i].length() - 2) + "\"";
  535.                     }
  536.                     else
  537.                     {
  538.                         i++;
  539.                         break;
  540.                     }
  541.                 }
  542.             }
  543.  
  544.             array = getStringArray(args, startIndex, i - startIndex - 1);
  545.             buf   = new StringBuffer();
  546.             
  547.             for(i = 0; i < array.length; i++)
  548.             {
  549.                 buf.append(array[i]).append(' ');
  550.             }
  551.             
  552.             setArchiverArgs(buf.toString().trim());
  553.         }
  554.     }
  555.  
  556.     /**
  557.      * @author Symantec Internet Tools Division
  558.      * @version 1.0
  559.      * @since VCafe 3.0
  560.      */
  561.     class MicrosoftToolsOption
  562.         extends StringOption
  563.     {
  564.         /**
  565.          * @param args TODO
  566.          * @param startIndex TODO
  567.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  568.          * @since VCafe 3.0
  569.          */
  570.         public void parseArg(String[] args, int startIndex)
  571.             throws InvalidArgumentException
  572.         {
  573.             setMicrosoftTools(getString(args, startIndex));
  574.         }
  575.     }
  576.  
  577. //    /**
  578. //     * @author Symantec Internet Tools Division
  579. //     * @version 1.0
  580. //     * @since VCafe 3.0
  581. //     */
  582. //    class NetscapeToolsOption
  583. //        extends StringOption
  584. //    {
  585. //        /**
  586. //         * @param args TODO
  587. //         * @param startIndex TODO
  588. //         * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  589. //         * @since VCafe 3.0
  590. //         */
  591. //        public void parseArg(String[] args, int startIndex)
  592. //            throws InvalidArgumentException
  593. //        {
  594. //            setNetscapeTools(getString(args, startIndex));
  595. //        }
  596. //    }
  597.  
  598.     /**
  599.      * @author Symantec Internet Tools Division
  600.      * @version 1.0
  601.      * @since VCafe 3.0
  602.      */
  603.     class SunToolsOption
  604.         extends StringOption
  605.     {
  606.         /**
  607.          * @param args TODO
  608.          * @param startIndex TODO
  609.          * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  610.          * @since VCafe 3.0
  611.          */
  612.         public void parseArg(String[] args, int startIndex)
  613.             throws InvalidArgumentException
  614.         {
  615.             setSunTools(getString(args, startIndex));
  616.         }
  617.     }
  618.  
  619.     public Archiver()
  620.         throws IOException
  621.     {
  622.         options = new Options();
  623.     }
  624.  
  625.     /**
  626.      * @param args TODO
  627.      * @since VCafe 3.0
  628.      */
  629.     protected boolean parseArgs(String[] args)
  630.     {
  631.         try
  632.         {
  633.             super.parseArgs(args);
  634.         }
  635.         catch(InvalidArgumentException ex)
  636.         {
  637.             if(ex instanceof MissingArgumentsException)
  638.             {
  639.                 showUsage();
  640.             }
  641.             else
  642.             {
  643. //                Debug.logException(ex);
  644.             }
  645.  
  646.             return (false);
  647.         }
  648.  
  649.         return (true);
  650.     }
  651.  
  652.     /**
  653.      * @since VCafe 3.0
  654.      */
  655.     public Option[] getOptions()
  656.     {
  657.         try
  658.         {
  659.             Properties properties;
  660.             Properties arg;
  661.             Option[]   options;
  662.             Option     defaultOption;
  663.  
  664.             properties = new Properties("/com/symantec/itools/tools/archive/Args.properties");
  665.             properties = properties.getProperties("arguments");
  666.             options    = new Option[16];
  667.  
  668.             arg        = properties.getProperties("type");
  669.             options[0] = new TypeOption();
  670.             getArg(options[0], arg);
  671.  
  672.             arg        = properties.getProperties("out");
  673.             options[1] = new OutOption();
  674.             getArg(options[1], arg);
  675.  
  676.             arg        = properties.getProperties("tempdir");
  677.             options[2] = new TempDirOption();
  678.             getArg(options[2], arg);
  679.  
  680.             arg        = properties.getProperties("classpath");
  681.             options[3] = new ClasspathOption();
  682.             getArg(options[3], arg);
  683.  
  684.             arg        = properties.getProperties("verbose");
  685.             options[4] = new VerboseOption();
  686.             getArg(options[4], arg);
  687.  
  688.             arg        = properties.getProperties("files");
  689.             options[5] = new FilesOption();
  690.             getArg(options[5], arg);
  691.  
  692.             arg        = properties.getProperties("entries");
  693.             options[6] = new EntriesOption();
  694.             getArg(options[6], arg);
  695.  
  696.             arg         = properties.getProperties("signer");
  697.             options[7] = new SignerOption();
  698.             getArg(options[7], arg);
  699.  
  700.             arg        = properties.getProperties("overwrite");
  701.             options[8] = new OverwriteOption();
  702.             getArg(options[8], arg);
  703.  
  704.             arg         = properties.getProperties("debug");
  705.             options[9] = new DebugOption();
  706.             getArg(options[9], arg);
  707.  
  708.             arg        = properties.getProperties("debuglog");
  709.             options[10] = new DebugLogOption();
  710.             getArg(options[10], arg);
  711.  
  712.             arg         = properties.getProperties("help");
  713.             options[11] = new HelpOption();
  714.             getArg(options[11], arg);
  715.  
  716.             arg         = properties.getProperties("mstools");
  717.             options[12] = new MicrosoftToolsOption();
  718.             getArg(options[12], arg);
  719.  
  720.             arg         = properties.getProperties("suntools");
  721.             options[13] = new SunToolsOption();
  722.             getArg(options[13], arg);
  723.  
  724.             arg         = properties.getProperties("archiverargs");
  725.             options[14] = new ArchiverArgsOption();
  726.             getArg(options[14], arg);
  727.  
  728.             arg         = properties.getProperties("signerargs");
  729.             options[15] = new SignerArgsOption();
  730.             getArg(options[15], arg);
  731.  
  732. //            arg         = properties.getProperties("nstools");
  733. //            options[13] = new NetscapeToolsOption();
  734. //            getArg(options[13], arg);
  735.  
  736.             arg           = properties.getProperties("default");
  737.             defaultOption = new Archiver.ResponseFileOption();
  738.             defaultOption.setFlags(arg.getStringList("flags", new String[] {""}));
  739.             defaultOption.setShortDesc(arg.getString("shortdesc"));
  740.             defaultOption.setLongDesc(arg.getString("longdesc"));
  741.             defaultOption.setHelp(arg.getString("help"));
  742.             setDefaultOption(defaultOption);
  743.  
  744.             return (options);
  745.         }
  746.         catch(IOException ex)
  747.         {
  748. //            Debug.logException(ex);
  749.         }
  750.  
  751.         return (null);
  752.     }
  753.  
  754.     /**
  755.      * @since VCafe 3.0
  756.      */
  757.     protected void getArg(Option option, Properties arg)
  758.     {
  759.         option.setFlags(arg.getStringList("flags"));
  760.         option.setMandatory(arg.getBoolean("mandatory"));
  761.         option.setDefaultValue(arg.getStringList("defaults"));
  762.         option.setShortDesc(arg.getString("shortdesc"));
  763.         option.setLongDesc(arg.getString("longdesc"));
  764.         option.setHelp(arg.getString("help"));
  765.     }
  766.  
  767.     /**
  768.      * @param errorMsg TODO
  769.      * @exception com.symantec.itools.lang.DynamicClassException
  770.      * @since VCafe 3.0
  771.      */
  772.     public boolean validate(StringBuffer errorMsg)
  773.         throws DynamicClassException
  774.     {
  775.         boolean retVal;
  776.  
  777.         validatorType = options.getValidator();
  778.  
  779.         if(validatorType == null)
  780.         {
  781.             errorMsg.append("Invalid validator for " + options.getType() + " in Archiver" +
  782.                              AccessiblePlatform.getJavaVersion() + ".properties");
  783.             return (false);
  784.         }
  785.  
  786.         retVal        = validatorType.validate(errorMsg);
  787.         validatorType = null;
  788.  
  789.         return (retVal);
  790.     }
  791.  
  792.     /**
  793.      * @param errorMsg TODO
  794.      * @exception com.symantec.itools.lang.DynamicClassException
  795.      * @since VCafe 3.0
  796.      */
  797.     public boolean create(StringBuffer errorMsg)
  798.         throws DynamicClassException
  799.     {
  800.         boolean retVal;
  801.  
  802.         archiverType = options.getArchiver();
  803.  
  804.         if(archiverType == null)
  805.         {
  806.             errorMsg.append("Invalid Archiver for " + options.getType() + " in Archiver" +
  807.                             AccessiblePlatform.getJavaVersion() + ".properties");
  808.             return (false);
  809.         }
  810.  
  811.         retVal       = archiverType.create(errorMsg);
  812.         archiverType = null;
  813.  
  814.         return (retVal);
  815.     }
  816.  
  817.     /**
  818.      * @param errorMsg TODO
  819.      * @exception com.symantec.itools.lang.DynamicClassException
  820.      * @since VCafe 3.0
  821.      */
  822.     public boolean sign(StringBuffer errorMsg)
  823.         throws DynamicClassException
  824.     {
  825.         boolean retVal;
  826.  
  827.         signingType = options.getSign();
  828.  
  829.         if(signingType == null)
  830.         {
  831.             errorMsg.append("Invalid signer for " + options.getType() + " in Archiver" +
  832.                             AccessiblePlatform.getJavaVersion() + ".properties");
  833.             return (false);
  834.         }
  835.  
  836.         retVal      = signingType.sign(errorMsg);
  837.         signingType = null;
  838.  
  839.         return (retVal);
  840.     }
  841.  
  842.     /**
  843.      * @since VCafe 3.0
  844.      */
  845.     public void cancel()
  846.     {
  847.         if(validatorType != null)
  848.         {
  849.             validatorType.cancel();
  850.         }
  851.         else if(archiverType != null)
  852.         {
  853.             archiverType.cancel();
  854.         }
  855.         else if(signingType != null)
  856.         {
  857.             signingType.cancel();
  858.         }
  859.     }
  860.  
  861.     /**
  862.      * @param t TODO
  863.      * @since VCafe 3.0
  864.      */
  865.     public void setType(String t)
  866.     {
  867.         String str;
  868.  
  869.         str = t.toLowerCase();
  870.  
  871.         if(str.equals("directory"))
  872.         {
  873.             str = "dir";
  874.         }
  875.  
  876.         options.setType(str);
  877.     }
  878.  
  879.     /**
  880.      * @param f TODO
  881.      * @since VCafe 3.0
  882.      */
  883.     public void setVerbose(boolean f)
  884.     {
  885.         options.setVerbose(f);
  886.     }
  887.  
  888.     /**
  889.      * @param files TODO
  890.      * @since VCafe 3.0
  891.      */
  892.     public void setFiles(String[] files)
  893.     {
  894.         options.setFiles(files);
  895.     }
  896.  
  897.     /**
  898.      * @param entries TODO
  899.      * @since VCafe 3.0
  900.      */
  901.     public void setEntries(String[] entries)
  902.     {
  903.         options.setEntries(entries);
  904.     }
  905.  
  906.     /**
  907.      * @param f TODO
  908.      * @since VCafe 3.0
  909.      */
  910.     public void setDebug(boolean f)
  911.     {
  912.         options.setDebug(f);
  913.     }
  914.  
  915.     /**
  916.      * @param f TODO
  917.      * @since VCafe 3.0
  918.      */
  919.     public void setOverwrite(boolean f)
  920.     {
  921.         options.setOverwrite(f);
  922.     }
  923.  
  924.     /**
  925.      * @param location TODO
  926.      * @since VCafe 3.0
  927.      */
  928.     public void setOutputLocation(String location)
  929.     {
  930.         options.setOutputLocation(location);
  931.     }
  932.  
  933.     /**
  934.      * @param location TODO
  935.      * @since VCafe 3.0
  936.      */
  937.     public void setTempDir(String location)
  938.     {
  939.         options.setTempDir(location);
  940.     }
  941.  
  942.     /**
  943.      * @param location TODO
  944.      * @since VCafe 3.0
  945.      */
  946.     public String getTempDir()
  947.     {
  948.         return (options.getTempDir());
  949.     }
  950.  
  951.     /**
  952.      * @param cp TODO
  953.      * @since VCafe 3.0
  954.      */
  955.     public void setClasspath(String cp)
  956.     {
  957.         // remove quotes!
  958.         cp = cp.substring(1, cp.length() - 1);
  959.         options.setClasspath(cp);
  960.     }
  961.  
  962.     /**
  963.      * @param fileName TODO
  964.      * @since VCafe 3.0
  965.      */
  966.     public void setDebugLog(String fileName)
  967.     {
  968.         options.setDebugLog(fileName);
  969.     }
  970.     
  971.     /**
  972.      * @param str TODO
  973.      * @since VCafe 3.0
  974.      */
  975.     public void setSigner(String str)
  976.     {
  977.         options.setSigner(str);
  978.     }
  979.  
  980.     /**
  981.      * @param str TODO
  982.      * @since VCafe 3.0
  983.      */
  984.     public void setSignerArgs(String str)
  985.     {
  986.         // remove quotes!
  987.         str = str.substring(1, str.length() - 1);
  988.         options.setSignerArgs(str);
  989.     }
  990.  
  991.     /**
  992.      * @param str TODO
  993.      * @since VCafe 3.0
  994.      */
  995.     public void setArchiverArgs(String str)
  996.     {
  997.         // remove quotes!
  998.         str = str.substring(1, str.length() - 1);
  999.         options.setArchiverArgs(str);
  1000.     }
  1001.  
  1002.     /**
  1003.      * @since VCafe 3.0
  1004.      */
  1005.     public String getType()
  1006.     {
  1007.         return (options.getType());
  1008.     }
  1009.  
  1010.  
  1011.     /**
  1012.      * @since VCafe 3.0
  1013.      */
  1014.     public boolean isVerbose()
  1015.     {
  1016.         return (options.isVerbose());
  1017.     }
  1018.  
  1019.     /**
  1020.      * @since VCafe 3.0
  1021.      */
  1022.     public String[] getFiles()
  1023.     {
  1024.         return (options.getFiles());
  1025.     }
  1026.  
  1027.     /**
  1028.      * @since VCafe 3.0
  1029.      */
  1030.     public String[] getEntries()
  1031.     {
  1032.         return (options.getEntries());
  1033.     }
  1034.  
  1035.     /**
  1036.      * @since VCafe 3.0
  1037.      */
  1038.     public boolean isDebug()
  1039.     {
  1040.         return (options.isDebug());
  1041.     }
  1042.  
  1043.     /**
  1044.      * @since VCafe 3.0
  1045.      */
  1046.     public boolean isOverwrite()
  1047.     {
  1048.         return (options.isOverwrite());
  1049.     }
  1050.  
  1051.     /**
  1052.      * @since VCafe 3.0
  1053.      */
  1054.     public String getOutputLocation()
  1055.     {
  1056.         return (options.getOutputLocation());
  1057.     }
  1058.  
  1059.     /**
  1060.      * @since VCafe 3.0
  1061.      */
  1062.     public String getClasspath()
  1063.     {
  1064.         return (options.getClasspath());
  1065.     }
  1066.  
  1067.     /**
  1068.      * @since VCafe 3.0
  1069.      */
  1070.     public String getDebugLog()
  1071.     {
  1072.         return (options.getDebugLog());
  1073.     }
  1074.  
  1075.     /**
  1076.      * @since VCafe 3.0
  1077.      */
  1078.     public boolean isSigning()
  1079.     {
  1080.         return (options.isSigning());
  1081.     }
  1082.  
  1083.     /**
  1084.      * @since VCafe 3.0
  1085.      */
  1086.     public String getSigner()
  1087.     {
  1088.         return (options.getSigner());
  1089.     }
  1090.  
  1091.     /**
  1092.      * @since VCafe 3.0
  1093.      */
  1094.     public String getSignerArgs()
  1095.     {
  1096.         return (options.getSignerArgs());
  1097.     }
  1098.  
  1099.     /**
  1100.      * @since VCafe 3.0
  1101.      */
  1102.     public String getArchiverArgs()
  1103.     {
  1104.         return (options.getArchiverArgs());
  1105.     }
  1106.  
  1107.     /**
  1108.      * @param str TODO
  1109.      * @since VCafe 3.0
  1110.      */
  1111.     public void setMicrosoftTools(String str)
  1112.     {
  1113.         options.setMicrosoftTools(str);
  1114.     }
  1115.  
  1116.     /**
  1117.      * @since VCafe 3.0
  1118.      */
  1119.     public String getMicrosoftTools()
  1120.     {
  1121.         return (options.getMicrosoftTools());
  1122.     }
  1123.  
  1124. //    /**
  1125. //     * @param str TODO
  1126. //     * @since VCafe 3.0
  1127. //     */
  1128. //    public void setNetscapeTools(String str)
  1129. //    {
  1130. //        options.setNetscapeTools(str);
  1131. //    }
  1132.  
  1133. //    /**
  1134. //     * @since VCafe 3.0
  1135. //     */
  1136. //    public String getNetscapeTools()
  1137. //    {
  1138. //        return (options.getNetscapeTools());
  1139. //    }
  1140.  
  1141.     /**
  1142.      * @param str TODO
  1143.      * @since VCafe 3.0
  1144.      */
  1145.     public void setSunTools(String str)
  1146.     {
  1147.         options.setSunTools(str);
  1148.     }
  1149.  
  1150.     /**
  1151.      * @since VCafe 3.0
  1152.      */
  1153.     public String getSunTools()
  1154.     {
  1155.         return (options.getSunTools());
  1156.     }
  1157.  
  1158.     /**
  1159.      * @since VCafe 3.0
  1160.      */
  1161.     public void setResponseFile(String fileName)
  1162.         throws FileNotFoundException,
  1163.                IOException
  1164.     {       
  1165.         BufferedReader reader;
  1166.         
  1167.         reader = null;
  1168.         
  1169.         try
  1170.         {
  1171.             String         line;
  1172.             Vector         contents;
  1173.             String[]       rspArgs;
  1174.                         
  1175.             contents = new Vector();
  1176.             reader   = new BufferedReader(new FileReader(fileName));
  1177.                 
  1178.             while((line = reader.readLine()) != null)
  1179.             {
  1180.                 StringTokenizer tokenizer;
  1181.  
  1182.                 tokenizer = new StringTokenizer(line, " ");
  1183.  
  1184.                 while(tokenizer.hasMoreTokens())
  1185.                 {
  1186.                     contents.addElement(tokenizer.nextToken());
  1187.                 }
  1188.             }
  1189.  
  1190.             rspArgs = new String[contents.size()];
  1191.             contents.copyInto(rspArgs);
  1192.             parseArgs(rspArgs);
  1193.         }
  1194.         finally
  1195.         {
  1196.             if(reader != null)
  1197.             {
  1198.                 reader.close();
  1199.             }
  1200.         }
  1201.     }
  1202.  
  1203.     /**
  1204.      * @param listener TODO
  1205.      * @since VCafe 3.0
  1206.      */
  1207.     public void addArchiverListener(ArchiverListener listener)
  1208.     {
  1209.         options.addArchiverListener(listener);
  1210.     }
  1211.  
  1212.     /**
  1213.      * @param argv TODO
  1214.      * @exception java.lang.Exception
  1215.      * @since VCafe 3.0
  1216.      */
  1217.     public static void main(String[] argv)
  1218.         throws NotDirectoryException,
  1219.                FileNotFoundException,
  1220.                IOException
  1221.     {
  1222.         Archiver archiver;
  1223.  
  1224.         archiver = null;
  1225.  
  1226.         try
  1227.         {
  1228.             archiver = new Archiver();
  1229.  
  1230.             if(argv.length > 0)
  1231.             {
  1232.                 if(archiver.parseArgs(argv))
  1233.                 {
  1234.                     StringBuffer errorMsg;
  1235.                     boolean      retValue;
  1236.  
  1237.                     if(archiver.isDebug())
  1238.                     {
  1239.                         try
  1240.                         {
  1241.                             Debug.setWriter(archiver.getDebugLog());
  1242.                         }
  1243.                         catch(IOException ex)
  1244.                         {
  1245.                             ex.printStackTrace();
  1246.                             Debug.setWriter(System.err);
  1247.                             Debug.logWarning("Couldn't set debugLog to " + archiver.getDebugLog());
  1248.                         }
  1249.  
  1250.                         Debug.startLog(Archiver.class, VERSION);
  1251.                     }
  1252.  
  1253.                     errorMsg = new StringBuffer();
  1254.  
  1255.                     if((retValue = archiver.validate(errorMsg)))
  1256.                     {
  1257.                         if((retValue = archiver.create(errorMsg)))
  1258.                         {
  1259.                             if(archiver.isSigning())
  1260.                             {
  1261.                                 retValue = archiver.sign(errorMsg);
  1262.                             }
  1263.                         }
  1264.                     }
  1265.  
  1266.                     if(!(retValue))
  1267.                     {
  1268.                         System.err.println(errorMsg);
  1269.                     }
  1270.  
  1271.                     if(archiver.isDebug())
  1272.                     {
  1273.                         Debug.finishLog();
  1274.                     }
  1275.                 }
  1276.             }
  1277.             else
  1278.             {
  1279.                 archiver.showUsage();
  1280.             }
  1281.         }
  1282.         catch(Throwable ex)
  1283.         {
  1284.             ex.printStackTrace();
  1285.             Debug.logException(ex);
  1286.         }
  1287.         finally
  1288.         {
  1289.             if(archiver != null && archiver.options != null)
  1290.             {
  1291.                 if(archiver.options.getTempDir() != null)
  1292.                 {
  1293.                     new Directory(archiver.options.getTempDir()).deleteAll();
  1294.                 }
  1295.             }
  1296.         }
  1297.     }
  1298. }
  1299.